﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Com.Framework;
using Com.Library.DB.Manager;
using Com.Library.DB.PageAuth;
using Com.Web.coffinegurunaru.AppLogic.Page;

namespace Com.Web.coffinegurunaru.manager.manager
{
	public partial class pageauth : ManagerPage
	{
		public byte IsManager { get; set; }
		public int PageNo { get; set; }
		public int ManagerSN { get; set; }
		protected void Page_Load(object sender, EventArgs e)
		{
			IsManager = ManagerModel.GetInfo(this.WebCookies.ManagerSN, this.WebCookies.ManagerID).IsManager;

			ManagerSN = Request.QueryString["ManagerSN"].Parse(0);
			this.PageNo = Request.QueryString["PageNo"].Parse(1);

			if (this.IsManager != 1)
			{
				Response.Clear();
				Response.End();
			}
		}

		public List<PageMainTypeEntity> GetMainPageList()
		{
			return PageAuthModel.MainPageList();
		}

		public List<PageSubTypeEntity> GetSubPageList(int MainPageType)
		{
			List<PageSubTypeEntity> list = PageAuthModel.SubPageList(MainPageType);

			return list;
		}

		private List<PageAuthMainEntity> m_MainAuthList = null;
		public PageAuthMainEntity GetMainAuthInfo(int MainPageType)
		{
			if (m_MainAuthList == null)
			{
				m_MainAuthList = PageAuthModel.PageAuthMainList(ManagerSN);
			}

			foreach (PageAuthMainEntity item in m_MainAuthList)
			{
				if (MainPageType == item.MainPageType)
					return item;
			}

			PageAuthMainEntity retValue = new PageAuthMainEntity();
			retValue.SetData("n4ManagerSN", ManagerSN);
			retValue.SetData("n4MainPageType", MainPageType);
			retValue.SetData("CodeAuthType", 0);
			retValue.SetData("strManagerName", string.Empty);
			return retValue;
		}

		private int m_MainPageType = 0;
		private List<PageAuthSubEntity> m_SubAuthList = null;
		public PageAuthSubEntity GetSubAuthInfo(int MainPageType, int SubPageType)
		{
			if (m_MainPageType != MainPageType)
			{
				m_MainPageType = MainPageType;
				m_SubAuthList = PageAuthModel.PageAuthSubList(ManagerSN, m_MainPageType);
			}

			foreach (PageAuthSubEntity item in m_SubAuthList)
			{
				if ( MainPageType == item.MainPageType && SubPageType == item.SubPageType )
					return item;
			}

			PageAuthSubEntity retValue = new PageAuthSubEntity();
			retValue.SetData("n4ManagerSN", ManagerSN);
			retValue.SetData("n4MainPageType", MainPageType);
			retValue.SetData("n4SubPageType", SubPageType);
			retValue.SetData("CodeAuthType", 0);
			retValue.SetData("strManagerName", string.Empty);
			return retValue; 
		}

		public List<PageAuthSubEntity> m_CategoryAuthList { get; set; }
		public bool IsCategoryCheck(int CategoryType)
		{
			if (m_CategoryAuthList == null)
			{
				m_CategoryAuthList = PageAuthModel.PageAuthSubList(ManagerSN, 1000);
			}
			foreach (var item in m_CategoryAuthList)
			{
				if (item.SubPageType == CategoryType)
				{
					return item.CodeAuthType == 1 ? true : false;
				}
			}

			return false;
		}
	}
}
